package com.aplink.generic.util.objectrule;

import java.io.Serializable;
import java.util.ArrayList;

import com.aplink.generic.pojo.GenericObject;

public class TargetRuleCollection implements Serializable {
    private static final long serialVersionUID = -8073492826429740288L;
    private ArrayList<TargetRule> arrTargetRules;
    private String defaultTarget;

    public TargetRuleCollection() {
        this.defaultTarget = "";
        this.arrTargetRules = new ArrayList<TargetRule>();
    }

    public TargetRuleCollection(final String _defaultTarget,
            final ArrayList<TargetRule> _arrTargetRules) {
        this.defaultTarget = _defaultTarget;

        this.arrTargetRules = new ArrayList<TargetRule>();
        this.arrTargetRules = _arrTargetRules;

    }

    public ArrayList<TargetRule> getArrTargetRules() {
        return this.arrTargetRules;
    }

    public String getDefaultTarget() {
        return this.defaultTarget;
    }

    public String getTargetBaseOnPassedGenericObject(
            final GenericObject genericObject) {

        for (final TargetRule targetRule : this.arrTargetRules) {
            final boolean isSatisfied = targetRule
                    .isSatisfiedCondition(genericObject);
            if (isSatisfied) {
                return targetRule.getTargetActivity();
            }
        }

        return this.defaultTarget;
    }

    public void setArrTargetRules(final ArrayList<TargetRule> arrTargetRules) {
        this.arrTargetRules = arrTargetRules;
    }

    public void setDefaultTarget(final String defaultTarget) {
        this.defaultTarget = defaultTarget;
    }

}
